﻿using AttendanceAccounting.Classes;
using ClassMySQL;
using System.Data;

namespace TeacherLoad.Classes
{
    internal static class SendToServer
    {
        private static string database = ServerMySQL.Database;   // Название базы данных
        private static string sql = "";     // Команда SQL

        internal static bool AddStudent(Student student)
        {
            sql = $"INSERT INTO {database}.students " +
                $"(last_name, first_name, patronymic) " +
                $"VALUES ('{student.LastName}', '{student.FirstName}', " +
                $"'{student.Patronymic}')";
            return OperationResult(sql);
        }

        internal static bool EditStudent(Student student)
        {
            sql = $"UPDATE `{database}`.`students` SET " +
                $"`last_name` = '{student.LastName}', `first_name` = '{student.FirstName}', " +
                $"`patronymic` = '{student.Patronymic}' " +
                $"WHERE (id = '{student.Id}')";
            return OperationResult(sql);
        }

        internal static DataTable GetAttendance()
        {
            sql = $"SELECT * FROM {database}.skip";
            return ServerMySQL.GetData(sql);
        }

        internal static DataTable GetStudents()
        {
            sql = $"SELECT * FROM {database}.students";
            return ServerMySQL.GetData(sql);
        }

        //#region Работа со специальностью
        //internal static DataTable GetSpec()
        //{
        //    sql = $"SELECT * FROM {database}.specialties";
        //    return ServerMySQL.GetData(sql);
        //}
        //internal static bool AddSpec(Specialization spec)
        //{
        //    sql = $"INSERT INTO {database}.specialties " +
        //        $"(code, nameSpec, qualification) " +
        //        $"VALUES ('{spec.Code}', '{spec.NameSpec}', " +
        //        $"'{spec.Qualification}')";
        //    return OperationResult(sql);
        //}
        //internal static bool EditSpec(Specialization spec)
        //{
        //    sql = $"UPDATE `{database}`.`specialties` SET " +
        //        $"`code` = '{spec.Code}', `nameSpec` = '{spec.NameSpec}', " +
        //        $"`qualification` = '{spec.Qualification}' " +
        //        $"WHERE (id = '{spec.Id}')";
        //    return OperationResult(sql);
        //}
        //#endregion

        //#region Работа с автором
        ///// <summary>
        ///// Добавление автора в БД
        ///// </summary>
        ///// <param name="author"></param>
        ///// <returns></returns>
        ////internal static bool AddAuthor(Author author)
        ////{
        ////    sql = $"INSERT INTO {database}.authors " +
        ////        $"(last_name, first_name, patronymic, descript) " +
        ////        $"VALUES ('{author.LastName}', '{author.FirstName}', " +
        ////        $"'{author.Patronymic}', '{author.Description}')";
        ////    return OperationResult(sql);
        ////}

        ///// <summary>
        ///// Редактирование данных автора в БД
        ///// </summary>
        ///// <param name="author"></param>
        ///// <returns></returns>
        ////internal static bool EditAuthor(Author author)
        ////{
        ////    sql = $"UPDATE `{database}`.`authors` SET " +
        ////       $"`last_name` = '{author.LastName}', `first_name` = '{author.FirstName}', " +
        ////       $"`patronymic` = '{author.Patronymic}', `descript` = '{author.Description}' " +
        ////       $"WHERE (id = '{author.Id}')";
        ////    return OperationResult(sql);
        ////}
        //#endregion

        //#region Работа с жанром
        ///// <summary>
        ///// Добавление нового жанра в БД
        ///// </summary>
        ///// <param name="genreName"></param>
        ///// <returns></returns>
        ////internal static bool AddGenre(Genre genreName)
        ////{
        ////    sql = $"INSERT INTO {database}.genre " +
        ////        $"(genre_name) " +
        ////        $"VALUES ('{genreName.GenreName}')";
        ////    return OperationResult(sql);
        ////}

        ///// <summary>
        ///// Редактирование жанра в БД
        ///// </summary>
        ///// <param name="genreName"></param>
        ///// <returns></returns>
        ////internal static bool EditGenre(Genre genreName)
        ////{
        ////    sql = $"UPDATE `{database}`.`genre` SET " +
        ////       $"`genre_name` = '{genreName.GenreName}' " +
        ////       $"WHERE (id = '{genreName.Id}')";
        ////    return OperationResult(sql);
        ////}
        //#endregion

        /// <summary>
        /// Выполнение операции добавления, обновления и удаления.
        /// Возврат - успешность операции.
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        private static bool OperationResult(string sql)
        {
            if (ServerMySQL.CrudOperation(sql) > 0)
                return true;
            else return false;
        }
    }
}